<template>
  <div class="school">
    <h2>学校名称：{{ name }}</h2>
    <h2>学校地址：{{ schoolAddress }}</h2>
  </div>
</template>

<script>
import pubsub from 'pubsub-js'
export default {
  
  name: "School",
  data () {
      return {
         name:'123',
         schoolAddress:"456"
      }
  },
  props: ["getSchoolName"],
  mounted () {
    // this.$bus.$on('student',(value)=>{//这里可以是箭头函数也可以是一个函数但是要提前写好
    //    this.name=value
    // })
    this.pubId=pubsub.subscribe('student',(msgName,data)=>{//msgName消息名字，data数据
      this.name=data
    })//接受消息
  },
  beforeDestroy () {
    pubsub.unsubscribe(this.pubId)//这里需要id关
  }
};
</script>

<style scoped>
.school {
  background-color: aqua;
  padding: 5px;
}
</style>
